package Or

import (
	"database/sql"
	"db2s/global"
	"db2s/go-log/log"
	"db2s/outPut"
	"db2s/parDef"
	"reflect"
	"time"
)

var (
	DBType = "Oracle"
	vlog   string
)

var (
	WLog                 *log.Logger
	rowsStaticParameter  = map[string]any{}
	rowsDynamicParameter = map[string]any{}
	metaDynamicParameter = map[string]any{}
	metaStaticParameter  = map[string]any{}
	classModeParameter   = map[string]reflect.Value{
		"struct": reflect.ValueOf(singleDbStructParameter),
		"sync":   reflect.ValueOf(singleDbSyncParameter),
	}
	modeP = map[string]reflect.Value{
		"struct": reflect.ValueOf(StructP),
		"sync":   reflect.ValueOf(syncP),
	}
)

type columnTypeGroupS struct {
	name       string
	class      string //类型
	null       string //null值约束
	dispersion string //离散度
}
type QueryTable struct {
	Schema              string
	Table               string
	LowerCaseTableNames bool
	ColumnName          []string
	TableColumn         []map[string]string
	HotSqlBeginTime     string
	HostSqlEndTime      string
	DB                  *sql.DB
	LogThreadSeq        int64
	SqlExecStopTime     time.Duration
	MissIndexTablePx    string
	FixRows             int64
	Eas                 global.EncryptionProperties
	Scn                 string
	PartitionName       string
	PartitionId         string
}

type TableMeta struct {
	Schema              string
	Table               string
	LowerCaseTableNames bool
	ColumnName          []string
	TableColumn         []map[string]string
	IndexColumnDataType string
	SqlExecStopTime     time.Duration
	LogThreadSeq        int64
	event               string
	MissIndexTablePx    string
}

// SDOGeometry 定义 SDO_GEOMETRY 结构体
type SDOGeometry struct {
	SDOElemInfo interface{}  `json:"SDO_ELEM_INFO"` // nil 对应的 Go 类型
	SDOGType    string       `json:"SDO_GTYPE"`
	SDOOrdinate interface{}  `json:"SDO_ORDINATES"` // nil 对应的 Go 类型
	SDOPoint    global.Point `json:"SDO_POINT"`
	SDOSRID     string       `json:"SDO_SRID"`
}

// STGeometry 定义 SDO_GEOMETRY 结构体
type STGeometry struct {
	GEOM SDOGeometry `json:"GEOM"`
}

type partMethBaseResultS struct {
	FirPartResult           []global.PartitionNameRulesS
	SubPartResult           map[string][]global.PartitionNameRulesS
	MethResult              []string
	FirPartColumnNameResult []string
	SubPartColumnNameResult []string
	ColMetaResult           global.AllReturnResult
	ShardResult             []global.PartShardS
}
type partitionBaseMeta struct {
	columnMeta       []global.TableMeta
	partitionMeta    []global.GetPartitionMeta
	tableDistributed []global.GetTableDistributed
}

type (
	newExecSqlS struct {
		DB      *sql.DB
		options Options
	}
	SqlFilter struct {
		WhereSql string
		WhereAdd string
	}
	Object struct {
		Schema    string
		Table     string
		Partition string
	}
	Options struct {
		Scn      string
		StopTime time.Duration
		//Esa                 EncryptionProperties
		WhereSql            string
		WhereAdd            string
		SqlMode             bool
		TablePx             string
		FixRows             int64
		LowerCaseTableNames bool
		SqlLogBin           bool //是否忽略binlog
		RowsLimit           int
		SqlFilter           SqlFilter
		RepairMethod        string //应用sql修复方式
	}
	ExecDDL struct {
		Sql       string                `json:"sqlText"`
		FilePoint outPut.FileOperations `json:"-"`
	}
	Parameter struct {
		Con     *sql.DB `json:"-"`
		Object  Object  `json:"object"`
		Options Options `json:"options"`
		ExecDDL ExecDDL `json:"execDDL"`
	}
	TableMe struct {
		//Parameter Parameter `json:"parameter"`
	}
	ColumnMe struct {
		//Parameter Parameter `json:"parameter"`
	}
	IndexMe struct {
		//Parameter Parameter `json:"parameter"`
	}
	PartitionMe struct {
		//Parameter Parameter `json:"parameter"`
	}
	ViewMe struct {
		Parameter Parameter `json:"parameter"`
	}
	MViewMe struct {
		Parameter Parameter `json:"parameter"`
	}
	SeqMe struct{}
	JobMe struct {
		Parameter Parameter `json:"parameter"`
	}
	TriggerMe struct {
		Parameter Parameter `json:"parameter"`
	}
	ForeignMe struct {
		Parameter Parameter `json:"parameter"`
	}
	ProcedureMe struct {
		Parameter Parameter `json:"parameter"`
	}
	FuncMe struct {
		Parameter Parameter `json:"parameter"`
	}
	TypeMe struct {
		Parameter Parameter `json:"parameter"`
	}
	PackageMe struct {
		Parameter Parameter `json:"parameter"`
	}
	SumF struct {}
	GolF struct {}
	RowsF struct{}
	DmlF  struct{}
)

type (
	TablePartitionConfig struct {
		Schema           string   `json:"schema"`
		Table            string   `json:"table"`
		ShardName        string   `json:"shardName"`
		BackendTableName string   `json:"backendTableName"`
		TableObject      string   `json:"tableObject"`
		PartColumnGather []string `json:"partColumnGather"`
		SubPartMeth      string
	}
	partMethS struct {
		FirstMeth string `json:"first"`
		SubMeth   string `json:"sub"`
	}
	partRulesS struct {
		Name    string `json:"partName"` //分区名
		SubName string `json:"subPartName"`
		Seq     string `json:"seq"`    //分区序号
		SubSum  string `json:"subSum"` //分区数量
		Rules   string `json:"rules"`  //分区规则
	}
	newPartMetaBaseResultS struct {
		PartRule    any `json:"partRule"`
		SubPartRule any `json:"subPartRule"`
		PartMeth    any `json:"partMeth"`
		PartCol     any `json:"partCol"`
		SubPartCol  any `json:"subPartCol"`
	}
	modifyLogoRecord struct {
		Object   string //对象
		Logo     string //改动标识
		OldValue string
		NewValue string
		Reason   string //转换说明
	}
	MetaBaseInitResult struct {
		columnMeta      []parDef.ColumnMeta
		constraintsMeta []parDef.Constraints
		columnMetaMap   []parDef.ColMetaMapS
		indexMeta       []parDef.IndexColumnMe
		partMe          parDef.PartMetaData
		factor          int
		Character       string
		Collate         string
		Comment         string
		indexColumnUniq map[string]int
		modifyNotNull   []string
		switchRecord    []modifyLogoRecord
	}
)
type ExecSqlInputS struct {
	Ss           any
	Event        string
	GisValFunc   func(any) any
	SelectSqlStr string
	UpdateSqlStr []string
	InsertSqlStr []*string
	Expect       string
	ShardName    string
}
